<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>嵌套解构</title>
</head>
<body>
  <script>
    const person = {
      name: 'Matt',
      age: 27,
      job: {
        title: 'Sofeware engineer'
      }
    };
    const personCopy = {};

    ({
      name: personCopy.name,
      age: personCopy.age,
      job: personCopy.job
    } = person);

    // person.job 是对象引用，所以修改里面的属性 personCopy 也会影响
    person.job.title = 'Hacker';

    console.log(person);  // { name: 'Matt', age: 27, { title: 'Hacker' } }
    console.log(personCopy);  // { name: 'Matt', age: 27, { title: 'Hacker' } }

    // 嵌套结构
    let { job: { title } } = person;

    console.log(title);  // Hacker
  </script>
</body>
</html>